﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Prototype.Dialogs
{
    public partial class AssetViewerImage : Form
    {
        public AssetViewerImage()
        {
            InitializeComponent();
        }

        public void setImage(Image img, string name)
        {
            // Set Picture Display
            picPreview.Image = img;

            // Set Name Tag
            picName.Text = name;

            // Set Resolution Tag
            picResolution.Text = img.PhysicalDimension.ToString();

            // Get Max Res (the 150 is to give some margin around edge of form and desktop resolution)
            int MaxWidth = SystemInformation.PrimaryMonitorSize.Width - 150;
            int MaxHeight = SystemInformation.PrimaryMonitorSize.Height - 150;
            int ImageWidth = img.Width;
            int ImageHeight = img.Height + 90;

            if (ImageWidth > this.Size.Width && ImageHeight > this.Size.Height)
            {
                // Check if Image is bugger thanresolution (we include the 90 also for resizing it to fit with the forms components)
                if (ImageWidth > MaxWidth || ImageHeight > MaxHeight)
                {
                    // Image was bigger than resolution so we resize to resolution size.
                    this.Size = new System.Drawing.Size(MaxWidth, MaxHeight);
                }
                else
                {
                    // Image was not bigger than resolution, so resize for mto image size.
                    this.Size = new System.Drawing.Size(ImageWidth, ImageHeight);
                }
            }            
        }

        private void toolSizeMode_Click(object sender, EventArgs e)
        {
            if (picPreview.SizeMode.ToString() == "CenterImage")
            {
                this.picPreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                toolSizeMode.Text = "Center Image";
            }
            else
            {
                this.picPreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
                toolSizeMode.Text = "Stretch to Fit";
            }
        }
    }
}
